﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections;
using DTO;

namespace DAO
{
    public class KhachHang_DAO
    {
        public DataProvider _provider = new DataProvider();
        public KhachHang_DAO()
        {
            _provider.connect();
        }
        public DataTable GetCmbLoaiKH()
        {
            string s = "Select * from LoaiKH";
            return _provider.executeQuery(s);
           
        }
        public DataTable GetDanhSachKH()
        {
            string s = "Select MaKH,TenKH,TenLoaiKH,LoaiKH.MaLoaiKH,DienThoai, DiaChi, DacDiem "
                        + "from KhachHang, LoaiKH "
                        + "where KhachHang.MaLoaiKH = LoaiKH.MaLoaiKH order by MaKH desc ";

            return _provider.executeQuery(s);
        }
        public int proc_Ins_KhachHang(KhachHang_DTO dto)
        {
            return _provider.proc_Ins_KhachHang(dto);
        }
        public void XoaKhachHang(string MaKH)
        {

            string s = "DELETE FROM KhachHang WHERE MaKH ='" + MaKH + "'";
            _provider.executeNonQuey(s);
        }
        public void SuaKhachHang(KhachHang_DTO KhachHang)
        {
            string s = "UPDATE KhachHang SET TenKH=N'" + KhachHang.TenKH
                       + "',MaLoaiKH = N'" + KhachHang.MaLoaiKH
                       + "',DienThoai = N'" + KhachHang.DienThoai
                       + "',DiaChi = N'" + KhachHang.DiaChi
                       + "',DacDiem = N'" + KhachHang.DacDiem
                       + "'WHERE MaKH ='" + KhachHang.MaKH + "'";
            _provider.executeNonQuey(s);
        }


        //public void GetMaLoaiKH(string TenLoaiKH,ref string arr)
        //{
        //    string s = "Select MaLoaiKH from LoaiKH where TenLoaiKH = N'" + TenLoaiKH + "'";
        //    IDataReader reader = _provider.executeQueryRow(s);
        //     while (reader.Read())
        //     {
        //         arr = reader[0].ToString();
        //     }
        //     reader.Close();

        //}
      
    }
}
